<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title>
</title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" href="css/ui-base.css">
<link rel="stylesheet" href="css/ui-box.css">
<link rel="stylesheet" href="css/ui-color.css">
<link rel="stylesheet" href="css/ui-img.css">
<script src="js/jquery-2.0.0.js"></script>
<script src="js/iscroll.js"></script>
<script src="js/pull.js"></script>
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/zy_tmpl.js"></script>
<script></script>
</head>
<body class="um-vp" ontouchstart>

	
</body>
<script>
var comUrl="http://tm.ourstu.com/api.php/document/viewDocument?document_id=22";
var detUrl="http://tm.ourstu.com/api.php/document/listComment";
zy_init();
window.uexOnload=function(type){
	if(!type){
		uexWindow.setBounce("1");
		uexWindow.showBounceView("0","#FFF","0");
		uexWindow.showBounceView("1","#FFF","0");
	}
	loadWeibo();
}


function pinglun(){
	uexWindow.cbPrompt=function(opId,dataType,data){
      //{"num":"0","value":"xxx"}
      var obj = eval('('+data+')');
      console.log("选择的按钮在数组中的下标为："+obj.num+",输入值为："+obj.value);
    }
    uexWindow.prompt("评论","","说点什么呢！",["发送","取消"]);
}
function loadWeibo(){
		$.getJSON(comUrl,function(data)
		{
			if(data.success){
				window.localStorage["WeiBoDetail_document_id"]=data["document"]["document_id"];
			}
			
			var de=document.createElement('DIV');
			var doc=userToArt(data.document,data.document.user);
  			doc["ctime"]=addFriendlyTime(doc.create_time);
			
			var len=doc["comment_count"];
			
			for(var j=0;j<len;j++)
			{
				var obj=doc["comment"][j];
				userToArt(doc["comment"][j],doc["comment"][j]["user"]);
				doc["comment"][j]["ctime"]=addFriendlyTime(doc["comment"][j]["create_time"]);
				
			}
			var docu=zy_tmpl_s(tmpl_detail,doc,zy_tmpl_count(doc));
				de.innerHTML=docu;
				document.body.appendChild(de);
			if(len==0){//无评论时
				var d=document.createElement('DIV');
				var nocom=zy_tmpl_s(tmpl_com,doc,zy_tmpl_count(doc));
				d.innerHTML=com;
				document.body.appendChild(d);
			}
			else{//有评论时
				for(var i=0;i<len;i++){
				var d=document.createElement('DIV');
				
				var com=zy_tmpl_s(tmpl_com,doc["comment"][i],zy_tmpl_count(doc["comment"][i]));
				d.innerHTML=com;
				document.body.appendChild(d);
				}
			}
			
			
		},"json",function(e){
	
		},"GET","",true);
}

/*
将时间戳转化成友好时间
*/
function addFriendlyTime(obj){
	var da=obj;
	da=parseInt(da)*1000;
	da=new Date(da);
	var year=da.getFullYear();
	var month=da.getMonth()+1;
	var date=da.getDate();
	//var time=da.Date();
	var nowDate=new Date();
	if(year!=nowDate.getFullYear())
	{
		str=year+'-'+month+'-'+date;
		
		return str;
	}	
	else
	{
		var monthin=nowDate.getMonth()-month;
		if(monthin==0)
		{
			dayin=nowDate.getDate()-date;
			if(dayin==0)
			{
				
				
				return da.getHours()+':'+da.getMinutes();
			}
			else if(dayin==1)
			{
				return "昨天"+da.getHours()+':'+da.getMinutes();
			}
			else
			{	
				var m=parseInt(da.getMonth())+1;

				return m+'-'+da.getDate();
			}
		}
		else{
			var m=parseInt(da.getMonth())+1;
			
			return m+'-'+da.getDate();
		}
		
	}
}


/*
将父属性的一个对象内的所有属性转化成父属性的一个子属性
*/
function userToArt(father,son){
	father["uid"]=son.uid;
	father["username"]=son.username;
	var headUrl=son.avatar_url;
	if(headUrl=="http://tm.ourstu.com/Addons/Avatar/default.jpg")
			{
				father["HeadPic"]="css/image/default.png";
			}
			else{
				father["HeadPic"]=son.avatar_url;
			}
	return father;
}
function loadCom(){
	
}
var tmpl_detail='<div  class="ub umh5  unn b-gra c-wh uc-t1 uc-b1 ub-ver shadow" style="border:1px solid #c5c5c5;3px 3px 6px rgba(180, 178, 178, 0.76) ">'
		+'<div class="ub">'
			+'<div class="umw3 umh5 umar-a" style="margin:0.6em"><div class="uabs umw3 umh5"  style="background-image:url(${HeadPic});width:50px;height:50px"></div></div>'
			+'<div class="ub ub-f1 ub-ver">'
				+'<div class="ub" style="margin-top:0.4em; margin-left:0.3em">'
					+'<div class="ulev0 t-bla">${username}</div>'
					+'<div class="umw1"></div>'
					+'<div class="ub-f1"></div>'
					+'<div class="umw1"></div>'
				+'</div>'
				+'<div class="ub" style="margin-top:0.4em; margin-left:0.3em">'
					+'<div class="t-gra" style="font-size:0.7em; margin-top:0.5em">${ctime}</div>'
					+'<div class="umw1"></div>'
					+'<div class="ub-f1"></div>'
					+'<div class="umw1"></div>'
				+'</div>'
				+'<div class="ub-f1"></div>'
				
			+'</div>'
		+'</div>'
		+'<div class="ub-f1 " style="font-size:0.95em;marhin-right:0.4em; margin-left:0.6em;margin-top:0.3em;margin-bottom:0.3em; letter-spacing:0.15em">${content}</div>'
		+'<div style="margin-top:0.1em; border-bottom:1px solid #c5c5c5;display:block"></div>'
		+'<div class="ub " style="margin:0.3em;margin-left:0.5em">'
			+'<div class="ub ub-f1 umh3">'
				+'<div class="ub-f1 imgCom" style="background-position:left;"></div>'
				+'<div class="ub-f1 ">评论：</div>'
			+'</div>'
			+'<div class="ub-f3"></div>'
		'</div>';

var tmpl_com='<div style="margin-top:0.1em; border-bottom:1px solid #c5c5c5;display:block"></div>'
			+'<div class="ub c-wh">'
			+'<div class="umw3 umh5 umar-a" style="margin:0.6em"><div class="uabs umw3 umh5"  style="background-image:url(${HeadPic});width:50px;height:50px"></div></div>'
			+'<div class="ub ub-f1 ub-ver">'
				+'<div class="ub c-wh" style="margin-top:0.4em; margin-left:0.3em">'
					+'<div class="ulev0 t-bla">${username}</div>'
					+'<div class="umw1"></div>'
					+'<div class="ub-f1 tx-r ulev-1" style="color:#888989">${ctime}</div>'
				+'</div>'
				+'<div class="ub" style="margin:0.4em;">'
					+'<div class="t-gra" style="font-size:0.9em; margin-top:0.5em">${content}</div>	'	
				+'</div>'
			+'</div>'
		+'</div>'
	+'</div>';
	
	var tmple_no_com='<div  class="ub umh5  unn b-gra c-wh uc-t1 uc-b1 ub-ver shadow" style="border:1px solid #c5c5c5;3px 3px 6px rgba(180, 178, 178, 0.76) ">'
		+'<div class="ub">'
			+'<div class="umw3 umh5 umar-a" style="margin:0.6em"><div class="uabs umw3 umh5"  style="background-image:url(${HeadPic});width:50px;height:50px"></div></div>'
			+'<div class="ub ub-f1 ub-ver">'
				+'<div class="ub" style="margin-top:0.4em; margin-left:0.3em">'
					+'<div class="ulev0 t-bla">${username}</div>'
					+'<div class="umw1"></div>'
					+'<div class="ub-f1"></div>'
					+'<div class="umw1"></div>'
				+'</div>'
				+'<div class="ub" style="margin-top:0.4em; margin-left:0.3em">'
					+'<div class="t-gra" style="font-size:0.7em; margin-top:0.5em">${ctime}</div>'
					+'<div class="umw1"></div>'
					+'<div class="ub-f1"></div>'
					+'<div class="umw1"></div>'
				+'</div>'
				+'<div class="ub-f1"></div>'
				
			+'</div>'
		+'</div>'
		+'<div class="ub-f1 " style="font-size:0.95em; margin-left:0.6em;margin-top:0.3em;margin-bottom:0.3em; letter-spacing:0.15em">我可以很负责任的告诉大家，高圆圆是我老婆，少女时代也是我老婆！我可以很负责任的告诉大家，高圆圆是我老婆，少女时代也是我老婆！</div>'
		+'<div style="margin-top:0.1em; border-bottom:1px solid #c5c5c5;display:block"></div>'
		+'<div class="ub " style="margin:0.3em;margin-left:0.5em">'
			+'<div class="ub ub-f1 umh3">'
				+'<div class="ub-f1 imgCom" style="background-position:left;"></div>'
				+'<div class="ub-f1 ">评论：</div>'
			+'</div>'
			+'<div class="ub-f3"></div>'
		+'</div>'
		+'<div class="ub imgNoComPic">'
			+'<div class="imgNoComPic umh5" style="min-height: 15em;background-image: url(css/image/nocompic.png);">'
			+'</div>'
		+'</div>';
</script>
</html>
